Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2Hts = require("Hts");
var $2ADManager = require("ADManager");
var $2ADInterface = require("ADInterface");
var $2ByteConstant = require("ByteConstant");
var def_ByteAD = /* */function (_s$default) {
  babel_inherits(l, _s$default);
  var _super11 = babel_createSuper(l);
  function l() {
    var _this30;
    babel_classCallCheck(this, l);
    _this30 = _super11.apply(this, arguments);
    _this30.isToutiaio = false;
    _this30.bannerAd = null;
    _this30.rewardVideoAd = null;
    _this30.rewardVideoAd1 = null;
    _this30.insertIntervalTime = 0;
    _this30.vedioIsEnd = true;
    _this30.lastClickTime = 0;
    return _this30;
  }
  babel_createClass(l, [{
    key: "showNative",
    value: function showNative() {}
  }, {
    key: "initAd",
    value: function initAd() {
      this.login();
      l.videoTime = 0;
      this.createVideo();
    }
  }, {
    key: "createVideo",
    value: function createVideo() {
      console.log("createVideo1111:");
      // this.rewardVideoAd = tt.createRewardedVideoAd({
      //   adUnitId: $2ByteConstant.default.POSID_VedioAD
      // });
      this.rewardVideoAd = tt.createRewardedVideoAd({
        adUnitId: "11qhdojmj368604vb6"
      });
      console.log("createVideo2222:");
    }
  }, {
    key: "createVideo1",
    value: function createVideo1() {
      console.log("createVideo1111:");
      this.rewardVideoAd1 = tt.createRewardedVideoAd({
        adUnitId: $2ByteConstant.default.POSID_VedioAD1
      });
      console.log("createVideo2222:");
    }
  }, {
    key: "exitGame",
    value: function exitGame() {
      tt.exitMiniProgram({
        isFullExit: true
      });
    }
  }, {
    key: "is_app",
    value: function is_app() {
      var e = tt.getSystemInfoSync().appName;
      return !!["Toutiao", "news_article_lite", "XiGua"].includes(e);
    }
  }, {
    key: "login",
    value: function login() {
      tt.login({
        force: true,
        success(e) {
          console.log("login 调用成功".concat(e.code, " ").concat(e.anonymousCode));
        },
        fail(e) {
          console.log("login 调用失败");
        }
      });
    }
  }, {
    key: "checkFollowAwemeState",
    value: function checkFollowAwemeState(e) {
      tt.checkFollowAwemeState({
        success(t) {
          console.log("调用成功", t);
          e && e(t.hasFollowed);
        },
        fail(t) {
          console.log("调用失败", t);
          e && e(t.hasFollowed);
        }
      });
    }
  }, {
    key: "followAwemeUser",
    value: function followAwemeUser(e) {
      tt.openAwemeUserProfile({
        success(t) {
          console.log(t);
          e && e(t.hasFollowed);
        }
      });
    }
  }, {
    key: "joinGroup",
    value: function joinGroup(e) {
      var t = tt.getSystemInfoSync().appName;
      if (["Toutiao", "news_article_lite", "XiGua"].includes(t)) {
        e && e(false);
      } else {
        tt.joinGroup({
          groupid: "@4F9T0KDFDJBoPnLxMIFrF6f61WeGOvmKOpN0rw2vK1EWbPL91HbieWIujgn96zUFP+HB00ZPZYCLW7PMbWx3Ew==",
          success(t) {
            e && e(true);
          },
          fail(t) {
            e && e(false);
          }
        });
      }
    }
  }, {
    key: "addShortcut",
    value: function addShortcut() {
      tt.addShortcut({
        success() {
          console.log("success");
        },
        fail(e) {
          console.log("err===", e.errMsg);
          this.showToast("添加桌面失败");
        }
      });
    }
  }, {
    key: "checkShortCut",
    value: function checkShortCut() {
      var e = this;
      tt.checkShortcut({
        success(t) {
          if (!t.status.exist || t.status.needUpdate) {
            e.canAddShortCut = true;
          } else {
            this.showToast("已添加至桌面");
            e.canAddShortCut = false;
          }
        },
        fail(t) {
          e.canAddShortCut = false;
          this.showToast("添加桌面失败");
          console.log("检查快捷方式失败", t.errMsg);
        }
      });
    }
  }, {
    key: "requestSubscribeSystemMessage",
    value: function requestSubscribeSystemMessage() {
      throw new Error("Method not implemented.");
    }
  }, {
    key: "creatInsert",
    value: function creatInsert() {
      // this.insertAd = tt.createInterstitialAd({
      //   adUnitId: $2ByteConstant.default.POSID_InsertAD
      // });
      this.insertAd = tt.createInterstitialAd({
        adUnitId: "1j66nga7w9ui63624e"
      });
      this.log("creatInsert this.isToutiaio:" + this.isToutiaio);
    }
  }, {
    key: "canShowInsert",
    value: function canShowInsert() {
      var e = new Date().getTime();
      if (!(e - $2ADManager.default.instance.startTime < 3e4)) {
        if (e - this.insertIntervalTime < 6e4) {
          return console.log("插屏显示间隔时间不足"), false;
        } else {
          return console.log("可以显示插屏"), this.insertIntervalTime = new Date().getTime(), true;
        }
      }
      console.log("进游戏时间不足");
    }
  }, {
    key: "showInsert",
    value: function showInsert() {
      if (!this.canShowInsert()) {
        return;
      }
      this.log("插屏广告showInsert111222233");
      var e = this;
      this.creatInsert();
      this.insertAd.load().then(function () {
        e.insertAd.show();
        e.log("插屏广告加载完成，准备展示");
      }).catch(function (t) {
        e.log("插屏广告异常:" + JSON.stringify(t));
        if (e.insertAd) {
          e.insertAd.destroy();
          e.insertAd = null;
        }
      });
      this.insertAd.onError(function (t) {
        e.log("头条插屏广告加载出错： " + JSON.stringify(t));
        if (e.insertAd) {
          e.insertAd.destroy();
          e.insertAd = null;
        }
      });
      this.insertAd.onClose(function (t) {
        e.log("头条插屏广告关闭:" + t);
        if (e.insertAd) {
          e.insertAd.destroy();
          e.insertAd = null;
        }
      });
    }
  }, {
    key: "creatbanner",
    value: function creatbanner() {
      var _this31 = this;
      var e = tt.getSystemInfoSync().windowHeight;
      var t = tt.getSystemInfoSync().windowWidth;
      this.bannerAd = tt.createBannerAd({
        adUnitId: $2ByteConstant.default.POSID_BannerAD,
        adIntervals: 60,
        style: {
          width: 170,
          left: (t - 170) / 2
        }
      });
      console.log("hei===112221");
      this.bannerAd.onResize(function (a) {
        console.log("hei===", a.height);
        _this31.bannerAd.style.top = e - a.height + 60;
        _this31.bannerAd.style.left = (t - a.width) / 2;
      });
      this.bannerAd.onError(function (e) {
        _this31.bannerAd = null;
        console.log("initBanner err1:" + e);
      });
    }
  }, {
    key: "showBanner",
    value: function showBanner() {
      var _this32 = this;
      null != this.bannerAd && null != this.bannerAd || this.creatbanner();
      this.log("banner广告 4444422212222");
      this.bannerAd.onLoad(function () {
        _this32.bannerAd.show().then(function () {
          console.log("banner加载成功");
        }).catch(function (e) {
          _this32.bannerAd = null;
          console.log("showBanner err:" + JSON.stringify(e));
        });
      });
    }
  }, {
    key: "hideBanner",
    value: function hideBanner() {
      console.log("hideBanner");
      if (null != this.bannerAd) {
        this.bannerAd.destroy();
        this.bannerAd = null;
      }
    }
  }, {
    key: "destroyBanner",
    value: function destroyBanner() {
      null != this.bannerAd && this.bannerAd.destroy();
    }
  }, {
    key: "vedioEnd",
    value: function vedioEnd() {
      return this.vedioIsEnd;
    }
  }, {
    key: "recorderStart",
    value: function recorderStart() {
      console.log("录屏====");
      tt.getGameRecorderManager().onStart(function () {
        console.log("录屏开始");
        $2ByteConstant.default.startRecorderTime = new Date().getTime();
      });
      tt.getGameRecorderManager().start({
        duration: 300
      });
    }
  }, {
    key: "recorderStop",
    value: function recorderStop() {
      this.log("recorderStop");
      tt.getGameRecorderManager().onStop(function (e) {
        $2ByteConstant.default.video_path = e.videoPath;
        $2ByteConstant.default.endRecorderTime = new Date().getTime();
        console.log("1111==", $2ByteConstant.default.endRecorderTime - $2ByteConstant.default.startRecorderTime);
        $2ByteConstant.default.endRecorderTime;
        $2ByteConstant.default.startRecorderTime;
      });
      this.log("停止录屏");
      tt.getGameRecorderManager().stop();
    }
  }, {
    key: "share",
    value: function share(e) {
      var t = this;
      tt.shareAppMessage({
        channel: "video",
        title: $2ByteConstant.default.title,
        imageUrl: "",
        query: "",
        extra: {
          videoPath: $2ByteConstant.default.video_path,
          videoTopics: $2ByteConstant.default.videoTopics
        },
        success() {
          e && e();
          t.showToast("分享成功");
        },
        fail(e) {
          t.showToast("分享视频失败");
          $2Hts.default.instance.eventReport("分享取消");
          t.log(e);
        }
      });
    }
  }, {
    key: "isFastClick",
    value: function isFastClick() {
      return 0 !== this.lastClickTime && new Date().getTime() - this.lastClickTime < 2e3 || (this.lastClickTime = new Date().getTime(), false);
    }
  }, {
    key: "showVideo",
    value: function showVideo(e, t, a) {
      console.log("播放激励视频")
      var _this33 = this;
      if (this.isFastClick()) {
        return;
      }
      null != this.rewardVideoAd && null != this.rewardVideoAd || this.createVideo();
      console.log("showvideo====112");
      this.insertIntervalTime = new Date().getTime();
      this.rewardVideoAd.show().then(function () {
        cc.game.pause();
      }).catch(function (e) {
        cc.game.resume();
        console.log("广告组件出现问题", e);
        a && a();
      });
      this.rewardVideoAd.onError(function () {
        a && a();
        cc.game.resume();
      });
      var n = function n(a) {
        console.log("res==112", a);
        if (a && a.isEnded || undefined === a) {
          cc.game.resume();
          e && e();
          _this33.showToast("奖励领取成功");
        } else {
          _this33.showToast("播放中途退出");
          t && t();
          cc.game.resume();
        }
        _this33.rewardVideoAd.offClose(n);
        _this33.insertIntervalTime = new Date().getTime();
      };
      this.rewardVideoAd.onClose(n);
      this.rewardVideoAd.offError();
      this.rewardVideoAd.load();
    }
  }, {
    key: "showVideo1",
    value: function showVideo1(e, t, a) {
      var _this34 = this;
      if (this.isFastClick()) {
        return;
      }
      null != this.rewardVideoAd1 && null != this.rewardVideoAd1 || this.createVideo1();
      console.log("showvideo====112");
      this.insertIntervalTime = new Date().getTime();
      this.rewardVideoAd1.show().then(function () {
        cc.game.pause();
      }).catch(function (e) {
        cc.game.resume();
        console.log("广告组件出现问题", e);
        a && a();
      });
      this.rewardVideoAd1.onError(function () {
        a && a();
        cc.game.resume();
      });
      var n = function n(a) {
        console.log("res==112", a);
        if (a && a.isEnded || undefined === a) {
          cc.game.resume();
          e && e();
          _this34.showToast("奖励领取成功");
        } else {
          _this34.showToast("播放中途退出");
          t && t();
          cc.game.resume();
        }
        _this34.rewardVideoAd1.offClose(n);
        _this34.insertIntervalTime = new Date().getTime();
      };
      this.rewardVideoAd1.onClose(n);
      this.rewardVideoAd1.offError();
      this.rewardVideoAd1.load();
    }
  }, {
    key: "showToast",
    value: function showToast(e) {
      tt.showToast({
        title: e
      });
    }
  }, {
    key: "log",
    value: function log(e) {
      console.log("byteAD:" + e);
    }
  }]);
  return l;
}($2ADInterface.default);
exports.default = def_ByteAD;